package com.ztjava.auth;


import com.jfinal.aop.Duang;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.redis.Cache;
import com.jfinal.plugin.redis.Redis;
import com.jfinal.template.Engine;
import com.ztjava.auth.model.AuthDept;
import com.ztjava.auth.service.AuthService;
import com.ztjava.core.Constant;
import com.ztjava.core.base.BaseSub;
import com.ztjava.core.tool.ConfigTool;

public class Auth extends BaseSub{	
	public final static String SESSION_THIRD_ID = "SESSION_THIRD_ID";
	public final static String SESSION_THIRD_USER = "SESSION_THIRD_USER";
	@Override
	public void configConstant(Constants me) {
		
	}

	@Override
	public void configRoute(Routes me) {
		
	}

	@Override
	public void configEngine(Engine me) {
		
	}

	@Override
	public void configPlugin(Plugins me) {
		
	}

	@Override
	public void configInterceptor(Interceptors me) {
		
	}

	@Override
	public void configHandler(Handlers me) {
		
	}

	@Override
	public void afterJFinalStart() {
		AuthService authService = Duang.duang(AuthService.class);
		Cache cache = Redis.use();
		if(!cache.exists(Constant.R_USER)){
			authService.loadUserCache();
		}
		if(!cache.exists(Constant.R_PRE+"AUTH_APP")){
			authService.loadAppCache();
		}
		if(!cache.hexists(Constant.R_BASEDATA,"AUTH_DEPT")){
			ConfigTool.dbToBaseData("AUTH_DEPT", AuthDept.tablename, "id asc");
		}
		if(!cache.hexists(Constant.R_BASEDATA,"AUTH_DEPT_NUM")){
			ConfigTool.dbToBaseData("AUTH_DEPT_NUM","select num as value,name,enable_flag from "
							+ AuthDept.tablename + " order by sort asc,id asc");
		}

		
	}

	@Override
	public void startComplete() {
		
	}
}
